
package com.idealighter.game.games.happyfive.handler;

import com.idealighter.game.core.annotation.ResMsgHandler;
import com.idealighter.game.games.happyfive.dto.RoomInfo;
import com.idealighter.game.games.happyfive.dto.RoomTypeDetailInfo;
import com.idealighter.game.games.happyfive.message.ReqEnterRoomMsg;
import com.idealighter.game.games.happyfive.message.ResGameHallMsg;
import com.idealighter.game.message.core.ResMessage;
import com.idealighter.game.robot.common.PlayerPosition;
import com.idealighter.game.robot.core.Player;
import com.idealighter.game.robot.handler.ResMessageHandler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


@ResMsgHandler(507201)
public class ResGameHallHandler implements ResMessageHandler {

  private static final Logger LOG = LoggerFactory.getLogger(ResGameHallHandler.class);

  @Override
  public void action(Player player, ResMessage message) {
    ResGameHallMsg msg = (ResGameHallMsg) message;
    LOG.info("[欢乐五张]玩家[{}][{}]进入大厅成功", player.userName, player.playerId);
    player.position = PlayerPosition.HALL;
    // HappyFiveStrategy gameStrategy = (HappyFiveStrategy) player.gameStrategy;
    for (RoomTypeDetailInfo roomTypeDetailInfo : msg.getRoomTypes()) {
      for (RoomInfo roomInfo : roomTypeDetailInfo.getRooms()) {
        if (roomInfo.getRoomId() == player.roomId) {
          enterRoom(player, roomInfo);
          return;
        }
      }
    }
  }

  /**
   * 进入房间.
   * 
   * @param player .
   * @param roomInfo .
   */
  public void enterRoom(Player player, RoomInfo roomInfo) {
    ReqEnterRoomMsg msg = new ReqEnterRoomMsg();
    msg.setRoomId(roomInfo.getRoomId());
    player.sendMsg(msg);
  }
}
